import {observable,action,computed} from 'mobx'
import { ajax } from '../api';

class Advise{
    @observable adviseList:any=null;
    @observable userInfo:any=null;
    @observable myadvise:any=null;

    @action changeInfoAsync=async()=>{
        let res=await ajax.getUserinfo()
        res.code=200&&(this.userInfo=res.result)
        
    }
    @action getAdviseList=async()=>{
        let res=await ajax.adviselist()
        res.code=200&&(this.adviseList=res.result)
        
    }
    @action changeadvise= (payload:any) =>{
        this.adviseList = payload;
    }
    @observable filteradviseList:any=null;

    @action filtergetAdviseList=async(payload:any)=>{
        let res=await ajax.adviselist()
        res.code=200&&(this.filteradviseList=res.result.filter((v:any)=>v.info._id==payload).reverse())
    }
    @action getmyadvise=async()=>{
        this.changeInfoAsync()
        let res=await ajax.adviselist()
        res.code=200&&(this.myadvise=res.result.filter((v:any)=>v.info._id==this.userInfo._id).reverse())
    }
}

export default new Advise() 